package com.yida.gwj.expend.outside.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yida.gwj.expend.outside.domain.GwjMaintenanceFundsBusinessInfo;
import com.yida.gwj.expend.outside.enums.FlagStatusEnum;
import com.yida.gwj.expend.outside.mapper.GwjMaintenanceFundsBusinessInfoMapper;
import com.yida.gwj.expend.outside.service.IGwjMaintenanceFundsBusinessInfoService;

import cn.hutool.core.util.ObjectUtil;

/**
 * 维修资金使用申请工程信息Service业务层处理
 *
 * @author lgp
 * @date 2023-02-20
 */
@Service
public class GwjMaintenanceFundsBusinessInfoServiceImpl implements IGwjMaintenanceFundsBusinessInfoService {
    @Autowired
    private GwjMaintenanceFundsBusinessInfoMapper gwjMaintenanceFundsBusinessInfoMapper;

    /**
     * 查询维修资金使用申请工程信息
     *
     * @param businessInfoId 维修资金使用申请工程信息主键
     * @return 维修资金使用申请工程信息
     */
    @Override
    public GwjMaintenanceFundsBusinessInfo selectGwjMaintenanceFundsBusinessInfoByBusinessInfoId(Long businessInfoId) {
        return gwjMaintenanceFundsBusinessInfoMapper.selectGwjMaintenanceFundsBusinessInfoByBusinessInfoId(businessInfoId);
    }

    /**
     * 查询维修资金使用申请工程信息列表
     *
     * @param gwjMaintenanceFundsBusinessInfo 维修资金使用申请工程信息
     * @return 维修资金使用申请工程信息
     */
    @Override
    public List<GwjMaintenanceFundsBusinessInfo> selectGwjMaintenanceFundsBusinessInfoList(GwjMaintenanceFundsBusinessInfo gwjMaintenanceFundsBusinessInfo) {
        return gwjMaintenanceFundsBusinessInfoMapper.selectGwjMaintenanceFundsBusinessInfoList(gwjMaintenanceFundsBusinessInfo);
    }

    /**
     * 新增维修资金使用申请工程信息
     *
     * @param gwjMaintenanceFundsBusinessInfo 维修资金使用申请工程信息
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    // @CachePut(value = "gwj:maintenance_funds_business_info", key = "#gwjMaintenanceFundsBusinessInfo.bizId", unless =
    // "#result == null")
    @Override
    public GwjMaintenanceFundsBusinessInfo insertGwjMaintenanceFundsBusinessInfo(GwjMaintenanceFundsBusinessInfo gwjMaintenanceFundsBusinessInfo) {
        if (ObjectUtil.notEqual(gwjMaintenanceFundsBusinessInfoMapper.insertGwjMaintenanceFundsBusinessInfo(gwjMaintenanceFundsBusinessInfo), FlagStatusEnum.SUC.getCode())) {
            return null;
        }
        return gwjMaintenanceFundsBusinessInfoMapper.selectGwjMaintenanceFundsBusinessInfoByBusinessId(gwjMaintenanceFundsBusinessInfo.getBizId());
    }

    /**
     * 修改维修资金使用申请工程信息
     *
     * @param gwjMaintenanceFundsBusinessInfo 维修资金使用申请工程信息
     * @return 结果
     */
    // @CachePut(value = "gwj:maintenance_funds_business_info", key = "#gwjMaintenanceFundsBusinessInfo.bizId", unless =
    // "#result == null")
    @Override
    public GwjMaintenanceFundsBusinessInfo updateGwjMaintenanceFundsBusinessInfo(GwjMaintenanceFundsBusinessInfo gwjMaintenanceFundsBusinessInfo) {
        if (ObjectUtil.notEqual(gwjMaintenanceFundsBusinessInfoMapper.updateGwjMaintenanceFundsBusinessInfoByBusinessId(gwjMaintenanceFundsBusinessInfo), FlagStatusEnum.SUC.getCode())) {
            return null;
        }
        return gwjMaintenanceFundsBusinessInfoMapper.selectGwjMaintenanceFundsBusinessInfoByBusinessId(gwjMaintenanceFundsBusinessInfo.getBizId());
    }

    /**
     * 删除维修资金使用申请工程信息信息-通过业务ID
     *
     * @param bizId 维修资金使用申请工程信息主键
     * @return 结果
     */
    // @CacheEvict(value = "gwj:maintenance_funds_business", key = "#bizId", condition = "#result == 1")
    @Override
    public int deleteGwjMaintenanceFundsBusinessInfoByBusinessId(Long bizId) {
        return gwjMaintenanceFundsBusinessInfoMapper.deleteGwjMaintenanceFundsBusinessInfoByBusinessId(bizId);
    }

    // @Cacheable(value = "gwj:maintenance_funds_business_info", key = "#bizId", unless = "#result == null")
    @Override
    public GwjMaintenanceFundsBusinessInfo selectGwjMaintenanceFundsBusinessInfoByBusinessId(Long bizId) {
        return gwjMaintenanceFundsBusinessInfoMapper.selectGwjMaintenanceFundsBusinessInfoByBusinessId(bizId);
    }

    /**
     * 通过businessId修改维修资金使用申请工程信息
     *
     * @param gwjMaintenanceFundsBusinessInfo 维修资金使用申请工程信息
     * @return 结果
     */
    // @CachePut(value = "gwj:maintenance_funds_business_info", key = "#gwjMaintenanceFundsBusinessInfo.bizId", unless =
    // "#result == null")
    @Override
    public GwjMaintenanceFundsBusinessInfo updateGwjMaintenanceFundsBusinessInfoByBusinessId(GwjMaintenanceFundsBusinessInfo gwjMaintenanceFundsBusinessInfo) {
        if (ObjectUtil.notEqual(gwjMaintenanceFundsBusinessInfoMapper.updateGwjMaintenanceFundsBusinessInfoByBusinessId(gwjMaintenanceFundsBusinessInfo), FlagStatusEnum.SUC.getCode())) {
            return null;
        }
        return gwjMaintenanceFundsBusinessInfoMapper.selectGwjMaintenanceFundsBusinessInfoByBusinessId(gwjMaintenanceFundsBusinessInfo.getBizId());
    }

    /* 
     * 根据bizId获取对应得业务信息，带文件编号
     */
    @Override
    public GwjMaintenanceFundsBusinessInfo selectGwjMaintenanceFundsBusinessInfoByBizId(Long bizId) {
        return gwjMaintenanceFundsBusinessInfoMapper.selectGwjMaintenanceFundsBusinessInfoByBizId(bizId);
    }

    /* 
     * updateGwjMaintenanceFundsBusinessInfoByBizId
     */
    @Override
    public int updateGwjMaintenanceFundsBusinessInfoByBizId(GwjMaintenanceFundsBusinessInfo gwjMaintenanceFundsBusinessInfo) {
        return gwjMaintenanceFundsBusinessInfoMapper.updateGwjMaintenanceFundsBusinessInfoByBizId(gwjMaintenanceFundsBusinessInfo);
    }

    /* (non-Javadoc)
     * @see com.yida.gwj.expend.outside.service.IGwjMaintenanceFundsBusinessInfoService#getOwnerComments(java.lang.Long)
     */
    @Override
    public Map<String, String> getOwnerComments(Long bizId) {
        return gwjMaintenanceFundsBusinessInfoMapper.getOwnerComments(bizId);
    }
}
